#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
class Solution
{
public:
    int distanceBetweenBusStops(vector<int> &distance, int start, int destination)
    {
        if (start > destination)
        {
            swap(start, destination);
        }
        return min(accumulate(distance.begin() + start, distance.begin() + destination, 0),
                   accumulate(distance.begin(), distance.begin() + start, 0) +
                       accumulate(distance.begin() + destination, distance.end(), 0));
    }
};
int main()
{
    Solution s;

    vector<int> distance = {7, 10, 1, 12, 11, 14, 5, 0};
    int start = 7, destination = 2;
    cout << s.distanceBetweenBusStops(distance, start, destination) << endl;
    system("pause");
    return 0;
}
